package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.speaktoitcookbook.bean.DishStep;
import com.speaktoitcookbook.dao.IDishStepDao;
import com.speaktoitcookbook.dao.impl.DishStepDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 菜谱步骤做法数据操作代理类
 * 
 * @author 赛艳志
 * 
 */
public class DishStepDaoProxy implements IDishStepDao {
    private Connection conn;
    private IDishStepDao dao;

    public DishStepDaoProxy() {
        this.conn = Database.getInstance().getConnection();
        this.dao = new DishStepDaoImpl(conn);
    }

    @Override
    public boolean doCreate(DishStep step) {
        boolean result = false;
        if (null != step) {
            result = dao.doCreate(step);
        }

        Database.close(conn);
        return result;
    }

    @Override
    public boolean doUpdate(DishStep step) {
        boolean result = false;
        if (null != step) {
            result = dao.doUpdate(step);
        }

        Database.close(conn);
        return result;
    }

    @Override
    public boolean doDelete(long cookbookID, int stepNO) {
        boolean result = false;
        if ((cookbookID > 0) && (stepNO > 0)) {
            result = dao.doDelete(cookbookID, stepNO);
        }

        Database.close(conn);
        return result;
    }

    @Override
    public DishStep getDishStep(long cookbookID, int stepNO) {
        DishStep result = null;
        if ((cookbookID > 0) && (stepNO > 0)) {
            result = dao.getDishStep(cookbookID, stepNO);
        }

        Database.close(conn);
        return result;
    }

    @Override
    public List<DishStep> getDishStep(long cookbookID) {
        List<DishStep> result = null;
        if (cookbookID > 0) {
            result = dao.getDishStep(cookbookID);
        }

        Database.close(conn);
        return result;
    }
}
